import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  articleList: {},
  articleAccept: "",
  articleApprove: "",
  articleColumn: "",
  articleDel: "",
  articleReject: "",
  articleAdminAdd: "",
  articleRoleAdd: "",
  articleConfig: "",
  articleUpdate: "",
  articleView: {}
};

const getters = {
  articleList: state => state.articleList, //文章列表服务
  articleAccept: state => state.articleAccept, //文章采纳
  articleApprove: state => state.articleApprove, //文章审核—通过
  articleColumn: state => state.articleColumn, //栏目详情（如果是单页返回详情，如果是列表调用列表文章接口）
  articleDel: state => state.articleDel, //文章删除
  articleReject: state => state.articleReject, //文章审核-拒绝
  articleAdminAdd: state => state.articleAdminAdd, //管理员-文章添加
  articleRoleAdd: state => state.articleRoleAdd, //其他角色-文章添加
  articleConfig: state => state.articleConfig, //文章获取UEditorJS配置
  articleUpdate: state => state.articleUpdate, //文章修改
  articleView: state => state.articleView //文章详情
};

const actions = {
  //我的上报
  roleReportUsingPOSTS({ commit }, param) {
    return Api.roleReportUsingPOST(param).then(ret => {
      commit(types.UPDATE_ARTICLE_LIST_LIST, ret.data);
      return ret;
    });
  },

  //我的上报
  myReportUsingPOSTS({ commit }, param) {
    return Api.myReportUsingPOST(param).then(ret => {
      commit(types.UPDATE_ARTICLE_LIST_LIST, ret.data);
      return ret;
    });
  },

  //文章列表
  listArticleUsingPOSTS({ commit }, param) {
    return Api.getNewsArticlePageList(param).then(ret => {
      commit(types.UPDATE_ARTICLE_LIST_LIST, ret.data);
      return ret;
    });
  },
  //文章采纳
  acceptArticleUsingPOSTS({ commit }, param) {
    return Api.acceptArticleUsingPOST(param).then(ret => {
      return ret;
    });
  },
  //文章采纳-拒绝
  acceptRejectArticleUsingPOSTS({ commit }, param) {
    return Api.acceptRejectArticleUsingPOST(param).then(ret => {
      return ret;
    });
  },
  //文章审核-通过
  approveArticleUsingPOSTS({ commit }, param) {
    return Api.auditArticle(param).then(ret => {
      return ret;
    });
  },
  //栏目详情（如果是单页返回详情，如果是列表调用列表文章接口）
  viewArticleColUsingGETS({ commit }, param) {
    return Api.viewArticleColUsingGET(param).then(ret => {
      commit(types.UPDATE_ARTICLE_COLUMN_LIST, ret.data);
      return ret;
    });
  },
  //文章删除
  deleteArticleUsingPOSTS({ commit }, param) {
    return Api.deleteNewsArticleById(param).then(ret => {
      commit(types.UPDATE_ARTICLE_DEL_LIST, ret.data);
      return ret;
    });
  },
  //文章审核-拒绝
  rejectArticleUsingPOSTS({ commit }, param) {
    return Api.rejectArticleUsingPOST(param).then(ret => {
      return ret;
    });
  },
  //管理员-文章添加
  saveArticleAdminUsingPOSTS({ commit }, param) {
    return Api.saveArticleAdminUsingPOST(param).then(ret => {
      commit(types.UPDATE_ARTICLE_ADMIN_LIST, ret.data);
      return ret;
    });
  },
  //其他角色-文章添加
  saveArticleRoleUsingPOSTS({ commit }, param) {
    return Api.saveArticleRoleUsingPOST(param).then(ret => {
      return ret;
    });
  },
  //文章获取UEditorJS配置
  ueConfigArticleUsingGETS({ commit }, param) {
    return Api.ueConfigArticleUsingGET(param).then(ret => {
      commit(types.UPDATE_ARTICLE_CONFIG_LIST, ret.data);
      return ret;
    });
  },
  //文章修改
  updateArticleUsingPOSTS({ commit }, param) {
    return Api.updateArticleUsingPOST(param).then(ret => {
      commit(types.UPDATE_ARTICLE_UPDATE_LIST, ret.data);
      return ret;
    });
  },
  //文章详情
  viewArticleUsingGETS({ commit }, param) {
    return Api.getNewsArticleById(param).then(ret => {
      commit(types.UPDATE_ARTICLE_VIEW_LIST, ret.data);
      return ret;
    });
  },
  // 机构文章详情 
  viewInstitutionUsingGETS({ commit }, param) {
    return Api.getRecoveryArticleById(param).then(ret => {
      commit(types.UPDATE_ARTICLE_VIEW_LIST, ret.data);
      return ret;
    });
  }
};
const mutations = {
  [types.UPDATE_ARTICLE_LIST_LIST](state, payload) {
    state.articleList = payload;
  },
  [types.UPDATE_ARTICLE_ACCEPT_LIST](state, payload) {
    state.articleAccept = payload;
  },
  [types.UPDATE_ARTICLE_APPROVE_LIST](state, payload) {
    state.articleApprove = payload;
  },
  [types.UPDATE_ARTICLE_COLUMN_LIST](state, payload) {
    state.articleColumn = payload;
  },
  [types.UPDATE_ARTICLE_DEL_LIST](state, payload) {
    state.articleDel = payload;
  },
  [types.UPDATE_ARTICLE_REJECT_LIST](state, payload) {
    state.articleReject = payload;
  },
  [types.UPDATE_ARTICLE_ADMIN_LIST](state, payload) {
    state.articleAdminAdd = payload;
  },
  [types.UPDATE_ARTICLE_ROLE_LIST](state, payload) {
    state.articleRoleAdd = payload;
  },
  [types.UPDATE_ARTICLE_CONFIG_LIST](state, payload) {
    state.articleConfig = payload;
  },
  [types.UPDATE_ARTICLE_UPDATE_LIST](state, payload) {
    state.articleUpdate = payload;
  },
  [types.UPDATE_ARTICLE_VIEW_LIST](state, payload) {
    state.articleView = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
